package crack.lshape.yijian_mesh;

import java.io.IOException;

import math2.MathUtilities;
import fem2.AbstractStructuralCrackDemo;
import fem2.Element;
import fem2.MaterialModel;
import fem2.MeshPart;
import fem2.Model;
import fem2.Observer;
import fem2.StringUtilities;
import fem2.element.crack_sda.SKONConstantJumpCSTElementUsingRecoverStress;
import fem2.enu.State;
import fem2.enu.StressType;
import fem2.material.StVenantKirchhoffMM;
import fem2.material.SPRrecoveryMM;
import fem2.material.cohesive_law.CohesiveLaw;
import fem2.observer.GidStressObserver;
import fem2.observer.TimeStepObserver;
import fem2.strategies.Strategy;

public class LshapeTriMeshYijianSKONConstantJumpCSTElementRecover2AndJirasekExponentialCohesiveLaw
		extends LshapeTriMeshYijianSKONConstantJumpCSTElementAndJirasekExponentialCohesiveLaw {

	public LshapeTriMeshYijianSKONConstantJumpCSTElementRecover2AndJirasekExponentialCohesiveLaw() {
		meshFileName = "mesh1-skon-recover2-jirasek.msh";
	}

	@Override
	public Element createElement(MeshPart mp, MaterialModel mm, CohesiveLaw cl) {
		Element e = new SKONConstantJumpCSTElementUsingRecoverStress(mp, mm, cl);
		return e;
	}

	@Override
	public MaterialModel createMaterial(Model m) {
		double E = 25850;
		double nu = 0.18;
		double t = 200;
		State ss = State.PLANE_STRESS;
		MaterialModel mm = new SPRrecoveryMM(m, new StVenantKirchhoffMM(E, nu, t, 0, ss));
		return mm;
	}

	@Override
	public void addObservers(Model m, Strategy s, TimeStepObserver o) {
		super.addObservers(m, s, o);

		String meshName = StringUtilities.getFileName(meshFileName);

		Observer so = new GidStressObserver(m, o, projectDir, projectName, meshName,
				StressType.RECOVER_STRESS_ZZ);

		s.addObserver(so);
	}

	public static void main(String[] args) throws IOException {

		AbstractStructuralCrackDemo sample = new LshapeTriMeshYijianSKONConstantJumpCSTElementRecover2AndJirasekExponentialCohesiveLaw();

		// double[] lambda = MyLinAlg.createLambdaArray(7.5, 0.1, 7.8);
		// double[] lambda = MyLinAlg.createLambdaArray(7.5, 0.1, 7.6, 0.05,
		// 10);
		// double[] lambda = MyLinAlg.createLambdaArray(7.5, 0.1, 7.6, 0.05,
		// 15);
		// double[] lambda = MyLinAlg.createLambdaArray(7.5, 0.1, 7.6, 0.05,
		// 20);
		// double[] lambda = MyLinAlg.createLambdaArray(7.5, 0.1, 7.6, 0.05,
		// 25);
		// double[] lambda = MyLinAlg.createLambdaArray(7.5, 0.1, 7.6, 0.05,
		// 30);
		// double[] lambda = MyLinAlg.createLambdaArray(7.5, 0.1, 7.6, 0.05,
		// 35);
		// double[] lambda = MyLinAlg.createLambdaArray(7.5, 0.1, 7.6, 0.05,
		// 40);
		double[] lambda = MathUtilities.createLambdaArray(7.5, 0.1, 7.6, 0.05, 50); // very
																						// nice
																						// result

		sample.run(lambda);

	}
}
